package service

import (
	"app.com/api.v1/config"
	rpcClient "app.com/rpc.v1/rpc"
	"github.com/go-redis/redis"
	"log"
)

var ServiceLK *Service

type Service struct {
	RedisClient *redis.Client
	DemoService *DemoService
}

func init() {
	ServiceLK = newService()
}

func newService() *Service {
	rpcClientA, err := rpcClient.NewClient()
	if err != nil {
		return nil
	}

	s := &Service{
		RedisClient: newRedis(),
		DemoService: NewDemoService(rpcClientA),
	}
	return s
}

func newRedis() *redis.Client {
	rdb := redis.NewClient(config.AppConf.RedisConf)
	err := rdb.Ping().Err()
	if err != nil {
		log.Fatalf("mysql connect error: %v", err)
	}
	return rdb
}
